package cn.csg.iotplatform.module.system.controller.admin.security;

import cn.csg.iotplatform.framework.common.pojo.CommonResult;
import cn.csg.iotplatform.framework.common.util.object.BeanUtils;
import cn.csg.iotplatform.module.system.controller.admin.security.vo.SecurityConfigRespVO;
import cn.csg.iotplatform.module.system.dal.dataobject.security.SecurityConfigDO;
import cn.csg.iotplatform.module.system.service.security.SecurityConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;

import static cn.csg.iotplatform.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 获取安全配置")
@RestController
@RequestMapping("/system/security-config")
@Validated
public class SecurityConfigController {

    @Resource
    private SecurityConfigService securityConfigService;

    @PostMapping("/get")
    @Operation(summary = "查询安全配置项")
    @Parameter(name = "clientId",description = "客户端id",example = "iotplatform")
    @PermitAll
    public CommonResult<SecurityConfigRespVO> get(@RequestParam("clientId") String clientId) {
        SecurityConfigDO securityConfigDO = securityConfigService.getByClientId(clientId);
        return success(BeanUtils.toBean(securityConfigDO, SecurityConfigRespVO.class));
    }


}
